{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "# 闭包\n",
    "def sum_1(a):\n",
    "    def sum_2(b,c):\n",
    "        print(a+b+c)\n",
    "    return sum_2\n",
    "\n",
    "s = sum_1(2)\n",
    "s(3,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "start...\n",
      "my test func !!!\n",
      "end...\n"
     ]
    }
   ],
   "source": [
    "# 装饰器定义\n",
    "def timmer(func):\n",
    "    def wrapper():\n",
    "        print('start...')\n",
    "        func()\n",
    "        print('end...')\n",
    "    return wrapper\n",
    "\n",
    "# 装饰器使用\n",
    "@timmer\n",
    "def mytest():\n",
    "    print('my test func !!!')\n",
    "\n",
    "mytest()"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "f0831691c6bb6c483f09af1e7987fd76373eadc68cb706017f41b090bfe4d138"
  },
  "kernelspec": {
   "display_name": "Python 3.8.3 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
